use compiler::token;
use std::{env, fs};
use token::tokenize;

fn main() {
    let args: Vec<String> = env::args().collect();

    if args.len() < 2 {
        eprintln!("Usage: {} <filename>", args[0]);
        std::process::exit(1);
    }

    // 获取文件名
    let filename = &args[1];

    // 读取输入文件
    let input = fs::read_to_string(filename).expect("Failed to read file");

    // 词法分析
    let res = tokenize(&input);

    match res {
        Ok(tokens) => {
            for tok in tokens {
                eprintln!("{}", tok.info());
            }
        }
        Err(errors) => {
            for err in errors {
                eprintln!("{}", err);
            }
        }
    }
}
